﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Controller.Utils
{
    /// <summary>
    /// 字节数组
    /// </summary>
    public class ByteArrayUtils
    {

        /// <summary>
        /// 比较两个数组的内容
        /// </summary>
        /// <param name="sourceArray">源数组</param>
        /// <param name="sourcePos">源数组起始位置</param>
        /// <param name="targetArray">目标数组</param>
        /// <param name="targetPos">目标数组起始位置</param>
        /// <param name="len">长度</param>
        /// <returns></returns>
        public static bool ComparisonTo(byte[] sourceArray, int sourcePos, byte[] targetArray, int targetPos, int len)
        {
            if (sourceArray.Length - sourcePos < len) return false;
            if (targetArray.Length - targetPos < len) return false;
            for (int i = 0; i < len; i++)
            {
                if (sourceArray[sourcePos] != targetArray[targetPos]) return false;
                sourcePos++;
                targetPos++;
            }
            return true;
        }
    }
}
